

#[test]
pub fn test_provide() {
    let f = File::open("test_assets/389-ds-base-2.2.3-1.fc37.x86_64.rpm").unwrap();
    let mut buf = BufReader::new(f);
    // let header: Header<IndexTag> = Header::parse(&mut buf).unwrap();
    let p = RPMPackage::parse(&mut buf).unwrap();
    // dbg!(p.metadata.get_packager().unwrap());
    // dbg!(p.metadata.get_file_paths().unwrap());
    let names: &[String] = p
        .metadata
        .header
        .get_entry_data_as_string_array(IndexTag::RPMTAG_PROVIDENAME)
        .unwrap();
    let flags = p
        .metadata
        .header
        .get_entry_data_as_u32_array(IndexTag::RPMTAG_PROVIDEFLAGS)
        .unwrap();
    let versions = p
        .metadata
        .header
        .get_entry_data_as_string_array(IndexTag::RPMTAG_PROVIDEVERSION)
        .unwrap();
    let v = itertools::multizip((names, flags, versions))
        .try_fold::<Vec<(String, u32, String, String)>, _, Result<_, RPMError>>(
            Vec::with_capacity(names.len()),
            |mut acc, (name, flag_num, ver)| {
                let flag_str = if flag_num & RPMSENSE_LESS == RPMSENSE_LESS {
                    if flag_num & RPMSENSE_EQUAL == RPMSENSE_EQUAL {
                        "LE"
                    } else {
                        "LT"
                    }
                } else if flag_num & RPMSENSE_GREATER == RPMSENSE_GREATER {
                    if flag_num & RPMSENSE_EQUAL == RPMSENSE_EQUAL {
                        "GE"
                    } else {
                        "GT"
                    }
                } else if flag_num & RPMSENSE_EQUAL == RPMSENSE_EQUAL {
                    "EQ"
                } else {
                    "NULL"
                };
                acc.push((
                    name.to_owned(),
                    flag_num,
                    flag_str.to_owned(),
                    ver.to_owned(),
                ));
                Ok(acc)
            },
        )
        .unwrap();
    for (name, flag_num, flag_str, ver) in &v {
        println!("{}\t\t\t\t{}\t{}\t\t{}", name, flag_num, flag_str, ver);
    }
    dbg!(v.len());
    // dbg!(provide_name);
    // dbg!(provide_attrsx);
    // dbg!(provide_flags);
    // dbg!(provide_nevrs);
    // dbg!(provide_version);
    // k.iter().zip
    // dbg!(p.metadata.get_provide().unwrap());
}
#[test]
pub fn test_req() {
    let f = File::open("test_assets/libgcc-12.2.1-2.fc37.x86_64.rpm").unwrap();
    let mut buf = BufReader::new(f);
    // let header: Header<IndexTag> = Header::parse(&mut buf).unwrap();
    let p = RPMPackage::parse(&mut buf).unwrap();
    // dbg!(p.metadata.get_packager().unwrap());
    // dbg!(p.metadata.get_file_paths().unwrap());
    let rpms = p.metadata.get_provides().unwrap();
    for ele in &rpms {
        println!(
            "{}\t\t\t{:?}\t{:?}\t{:?}\t{:?}",
            ele.name, ele.flags, ele.epoch, ele.version, ele.release
        );
    }
    dbg!(rpms.len());
    // for (name, flag, flag_str, ver) in &v {
    //     println!("{}\t\t\t\t{}\t{}\t\t{}", name, flag, flag_str, ver);
    // }
    // dbg!(v.len());
}
#[test]
pub fn test_pre() {
    let f = File::open("test_assets/libgcc-12.2.1-2.fc37.x86_64.rpm").unwrap();
    let mut input = BufReader::new(f);
    let mut lead_buffer = [0; LEAD_SIZE];
    input.read_exact(&mut lead_buffer).unwrap();
    let lead = Lead::parse(&lead_buffer).unwrap();
    let signature_header = Header::parse_signature(&mut input).unwrap();
    let mut buf = Vec::new();
    input.read_to_end(&mut buf).unwrap();
    let mut pre = OpenOptions::new()
        .create(true)
        .append(true)
        .write(true)
        .open("test_assets/test_pre.bin")
        .unwrap();
    pre.write(&buf).unwrap();
}
#[test]
pub fn test_blob() {
    let mut f = File::open("test_assets/test_2.bin").unwrap();
    let mut v = vec![0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00];
    // BufReader::new(b);
    f.read_to_end(v.as_mut()).unwrap();
    let mut input = Cursor::new(v);
    let h: Header<IndexTag> = Header::parse(&mut input).unwrap();
    dbg!(h.get_provides().unwrap());
    dbg!(h.get_requires().unwrap());
    // RPMPackage::open(path)
    // RPMPackageMetadata::
    // let mut input = BufReader::new(f);
    // let src: [u8; 8] = [0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00];
    // input.buffer().copy_from_slice(src.as_ref());
    // let k = input.borrow_mut().buffer();
    // k.copy_from_slice(&src);
    // let mut buf: [u8; 16] = [0; 16];
    // input.read_exact(&mut buf).unwrap();
    // let mut b;
    // let (num, head_size) = parse_blob(&buf).unwrap();
    // let mut buf = vec![0; (head_size + num * 16) as usize];
    // input.read_exact(&mut buf).unwrap();
    // Header::parse_header(index_header, bytes);
    // let k = buf.as_ref();
    // let (rest, num) = be_u32(buf.as_ref()).unwrap();
}
// pub fn parse_blob(input: &[u8]) -> Result<(u32, u32), RPMError> {
//     let (rest, num) = be_u32(input)?;
//     let (_rest, header_size) = be_u32(input)?;
//     Ok((num, header_size))
// }
#[test]
pub fn test() {
    let ver = "7.0.6";
    let mut epoch = "";
    let mut version = "";
    let mut release = "";
    if ver != "" {
        let rest = match ver.split_once(":") {
            Some((e, rest)) => {
                epoch = e;
                rest
            }
            None => {
                epoch = "0";
                ver
            }
        };
        match rest.split_once("-") {
            Some((v, r)) => {
                version = v;
                release = r;
            }
            None => {
                version = rest;
            }
        }
    }

    dbg!(epoch);
    dbg!(version);
    dbg!(release);
}
